package com.jn.mvvm2.views;

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import com.jn.mvvm2.R;
import com.jn.mvvm2.databinding.ActivityInputBinding;
import com.jn.mvvm2.model.InputViewModel;
import com.jn.mvvm2.views.PetListActivity;

public class InputActivity extends AppCompatActivity {
    private InputViewModel inputViewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityInputBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_input);
        inputViewModel = new ViewModelProvider(this).get(InputViewModel.class);
        binding.setViewModel(inputViewModel);
        binding.setLifecycleOwner(this);

        String url = getIntent().getStringExtra("url");
        inputViewModel.setUrl(url);

        binding.searchButton.setOnClickListener(v -> {
            String type = binding.typeEditText.getText().toString();
            String page = binding.pageEditText.getText().toString();
            String num = binding.numEditText.getText().toString();
            String name = binding.nameEditText.getText().toString();

            Intent intent = new Intent(InputActivity.this, PetListActivity.class);
            intent.putExtra("url", url);
            intent.putExtra("type", type);
            intent.putExtra("page", page);
            intent.putExtra("num", num);
            intent.putExtra("name", name);
            startActivity(intent);
        });
    }
}